package com.xsmart.oa.dao;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 服务列表
 *
 * @author guojd
 */
@Component
public interface ServiceListCtrlDao {
    /**
     * 添加api
     * @param apiInfo
     * @return
     */
    @Insert("INSERT INTO cfgs_services_list(service_name,service_uri,service_url,servcie_modular, service_method_name, service_status, service_version, is_check_login, is_log, service_terminal) " +
            "VALUES (#{service_name},#{service_uri},#{service_url},#{servcie_modular},#{service_method_name},#{service_status},#{service_version},#{is_check_login},#{is_log},#{service_terminal})")
    int addApi(Map<String, Object> apiInfo);

    /**
     * 更新api
     * @param serviceId
     * @param apiInfo
     * @return
     */
    @Update("UPDATE cfgs_services_list SET service_name=#{apiInfo.service_name},\n" +
            "service_method_name=#{apiInfo.service_method_name},\n" +
            "service_uri=#{apiInfo.service_uri},\n" +
            "service_url=#{apiInfo.service_url},\n" +
            "servcie_modular=#{apiInfo.servcie_modular},\n" +
            "service_status=#{apiInfo.service_status},\n" +
            "service_version=#{apiInfo.service_version},\n" +
            "is_check_login=#{apiInfo.is_check_login},\n" +
            "is_log=#{apiInfo.is_log},\n" +
            "service_terminal=#{apiInfo.service_terminal}" +
            " WHERE service_id=#{serviceId}")
    int modApi(@Param("serviceId") int serviceId, @Param("apiInfo") Map<String, Object> apiInfo);

    /**
     * 删除api
     * @param serviceId
     * @return
     */
    @Delete("DELETE FROM cfgs_services_list WHERE service_id=#{serviceId}")
    int delApi(@Param("serviceId") int serviceId);

    /**
     * 查询api列表
     * @param page
     * @param serviceMap
     * @return
     */
    @Select("<script>" +
            "SELECT * FROM cfgs_services_list " +
            "where 1=1 <if test=\"serviceName!=null and serviceName!=''\">and service_name=#{serviceName}</if> " +
            "<if test=\"serviceStatus!=null\">and service_status=#{serviceStatus}</if> " +
            "order by service_name asc,service_method_name desc,service_version desc " +
            "</script>")
    List<Map<String, Object>> queryServiceList(Pagination page,Map serviceMap);

    /**
     * 查询api列表
     * @return
     */
    @Select("SELECT * FROM cfgs_services_list")
    List<Map<String, Object>> getApiInfoList();

    /**
     * 查询api信息
     * @param serviceId
     * @return
     */
    @Select("SELECT * FROM cfgs_services_list WHERE service_id=#{serviceId}")
    Map<String, Object> getApiInfo(@Param("serviceId") int serviceId);

    /**
     * 新增服务接口api
     * @param serviceMap
     * @return
     */
    @Insert("INSERT INTO cfgs_services_list" +
            "(service_uri," +
            "service_name," +
            "service_method_name," +
            "service_status," +
            "service_version," +
            "service_url," +
            "servcie_modular," +
            "is_check_login," +
            "is_log," +
            "service_terminal," +
            "service_desc)" +
            "VALUES" +
            "(#{serviceMap.service_uri}," +
            "#{serviceMap.service_name}," +
            "#{serviceMap.service_method_name}," +
            "#{serviceMap.service_status}," +
            "#{serviceMap.service_version}," +
            "#{serviceMap.service_url}," +
            "#{serviceMap.servcie_modular}," +
            "#{serviceMap.is_check_login}," +
            "#{serviceMap.is_log}," +
            "#{serviceMap.service_terminal}," +
            "#{serviceMap.service_desc})")
    int addServiceList(@Param("serviceMap") Map<String, Object> serviceMap);

    /**
     * 修改服务接口api
     * @param serviceMap
     * @return
     */
    @Insert("update cfgs_services_list " +
            "set " +
            "service_uri = #{serviceMap.service_uri}, " +
            "service_name = #{serviceMap.service_name}," +
            "service_method_name = #{serviceMap.service_method_name}," +
            "service_status = #{serviceMap.service_status}," +
            "service_version = #{serviceMap.service_version}," +
            "service_url = #{serviceMap.service_url}," +
            "servcie_modular = #{serviceMap.servcie_modular}," +
            "is_check_login = #{serviceMap.is_check_login}," +
            "is_log = #{serviceMap.is_log}," +
            "service_terminal = #{serviceMap.service_terminal}," +
            "service_desc = #{serviceMap.service_desc} " +
            "where service_id = #{serviceMap.service_id}")
    int modServiceList(@Param("serviceMap") Map serviceMap);

    /**
     * 删除服务接口api
     * @param serviceId
     * @return
     */
    @Delete("DELETE FROM cfgs_services_list WHERE service_id=#{serviceId}")
    int delServiceList(Integer serviceId);


}
